package com.mask.sca.member.controller;

import com.mask.sca.auth.api.feign.FeignAuthService;

import com.mask.sca.core.response.ApiResponse;
import com.mask.sca.core.vo.LoginParamVo;
import com.mask.sca.core.vo.RegisterParamVo;
import com.mask.sca.member.service.MemberService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author：jian
 * @Package：com.mask.sca.member.controller
 * @Project：mask-sca-cloud
 * @name：MemberLoginController
 * @Date：2025/7/25 16:10
 * @Filename：MemberLoginController
 */
@RestController
@RequestMapping("member")
public class MemberLoginController {

    @Resource
    private FeignAuthService authService;

    @Resource
    private MemberService memberService;

    @PostMapping("login")
    public ApiResponse<Map<String, Object>> postAccessToken(@RequestBody LoginParamVo loginParamVo){
        String username = loginParamVo.getUsername();
        String password = loginParamVo.getPassword();
        Map<String, Object> params = new HashMap<>();
        params.put("username", loginParamVo.getUsername());
        params.put("password", loginParamVo.getPassword());
        params.put("login_type","member");
        params.put("client_id", "client");
        params.put("client_secret", "secret");
        ApiResponse<Map<String, Object>> apiResponse = authService.passwordLogin(params);
        return apiResponse;
    }

    /**
     * 注册用户
     * @param registerParamVo
     * @return
     */
    @PostMapping("register")
    public ApiResponse<?> register(@RequestBody RegisterParamVo registerParamVo){
        memberService.addMember(registerParamVo);
        return ApiResponse.success();
    }
}
